<?php 
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use DB;


class Commonts extends Model {

	protected $table = 'commonts';
        const UPDATED_AT = null; 
	protected $fillable = array('collection_id', 'collection_user_id', 'user_id', 'commont','created_at');
        
        public function addcommont($params){
            $vote = $this->create($params);
            return $vote;
        }
        
        public function getUnreadNum($user_id) {
            $num = $this->where('collection_user_id', $user_id)
                    ->where('is_read', '0')
                    ->count();
            return $num;
        }
        
        public function updateread($user_id){
            DB::beginTransaction();
            $result = $this->where('collection_user_id',$user_id)->update(['is_read'=>'1']);
            DB::commit();
            return $result;
        }

}